package edu.ccut.titan.tag.report.tag;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import edu.ccut.titan.tag.report.design.ChartsInfo;
import edu.ccut.titan.tag.report.design.SeriesInfo;

@SuppressWarnings("serial")
public class TitanReportChartTag extends TagSupport {
	private String type;
	private String title;
	private String categoryTitle;
	private String seriesTitle;
	private List<SeriesInfo> series;
	private TitanReportTag reportTag;
	private ChartsInfo chart;
	private String height;
	private String width;
	private String x;
	private String y;

	public String getX() {
		return x;
	}

	public void setX(String x) {
		this.x = x;
	}

	public String getY() {
		return y;
	}

	public void setY(String y) {
		this.y = y;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public int doStartTag() throws JspException {
		series = new ArrayList<SeriesInfo>();
		chart = new ChartsInfo();
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {
		reportTag = (TitanReportTag) this.getParent();
		if (type != null) {
			chart.setType(type);
		}
		if (title != null) {
			chart.setTitle(title);
		}
		if (categoryTitle != null) {
			chart.setCategoryTitle(categoryTitle);
		}
		if (series.size() > 0) {
			chart.setSeries(series);
		}
		if (seriesTitle != null) {
			chart.setSeriesTitle(seriesTitle);
		}
		if (width != null) {
			chart.setWidth(width);
		}
		if (height != null) {
			chart.setHeight(height);
		}
		if (x != null) {
			chart.setX(x);
		}
		if (y != null) {
			chart.setY(y);
		}

		reportTag.addChartInfo(chart);
		return SKIP_BODY;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void addSeriesInfo(SeriesInfo seriesInfo) {
		series.add(seriesInfo);
	}

	public String getCategoryTitle() {
		return categoryTitle;
	}

	public void setCategoryTitle(String categoryTitle) {
		this.categoryTitle = categoryTitle;
	}

	public String getSeriesTitle() {
		return seriesTitle;
	}

	public void setSeriesTitle(String seriesTitle) {
		this.seriesTitle = seriesTitle;
	}

	public List<SeriesInfo> getSerieses() {
		return series;
	}

	public void setSerieses(List<SeriesInfo> serieses) {
		this.series = serieses;
	}
}
